// src/api/course.js
import axios from 'axios';

const API_BASE = '/teach';

export const courseApi = {
  // 获取课程列表 - 对应后端 GET /course/list
  getCourses: (params = {}) => {
    return axios.get(`${API_BASE}/course/list`, { params });
  },

  // 新增课程 - 对应后端 POST /course
  createCourse: (courseData) => {
    return axios.post(`${API_BASE}/course`, courseData);
  },

  // 更新课程 - 对应后端 PUT /course
  updateCourse: (courseData) => {
    return axios.put(`${API_BASE}/course`, courseData);
  },

  // 删除课程 - 对应后端 DELETE /course/{courseId}
  deleteCourse: (courseId) => {
    return axios.delete(`${API_BASE}/course/${courseId}`);
  },

  // 更改课程状态 - 对应后端 PATCH /course/{courseId}/status
  updateCourseStatus: (courseId, status) => {
    return axios.patch(`${API_BASE}/course/${courseId}/status`, null, {
      params: { status }
    });
  },

  // 获取可选课程列表 - 对应后端 GET /course/available
  getAvailableCourses: (params = {}) => {
    return axios.get(`${API_BASE}/course/available`, { params });
  },

  // 学生选课 - 对应后端 POST /course/enroll
  enrollCourse: (courseId) => {
    return axios.post(`${API_BASE}/course/enroll`, null, {
      params: { courseId }
    });
  },

  // 获取已选课程列表 - 对应后端 GET /course/enrolled
  getEnrolledCourses: (params = {}) => {
    return axios.get(`${API_BASE}/course/enrolled`, { params });
  },

  // 学生退课 - 对应后端 POST /course/withdraw
  withdrawCourse: (courseId) => {
    return axios.post(`${API_BASE}/course/withdraw`, null, {
      params: { courseId }
    });
  }
};